// __PUBLIC__/js/page/admin/circle/circlelist
require(['../../common'], function() {
  require(['circle.circlemessagelist'])
})

define('circle.circlemessagelist', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';
  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init()

  function getSelected() {
    var selected = mygrid.getSelected()
    if (!selected.count) {
      alert(lang.pleaseSelectAData)
      return
    }
    return selected
  }

  function getASelected(t) {
    var current = mygrid.getCurrent(t)
    var selected = {
      id: [current.id],
      index: [current.index]
    }
    return selected
  }

  $(document)
    .on('click', '.A_del', function(e) {
      e.preventDefault()
      deleteCircle(getASelected(this))
    })
    .on('click', '#J_del', function(e) {
      e.preventDefault()
      var selected = getSelected()
      deleteCircle(selected)
    })

  function deleteCircle(selected) {
    $.post(APP + '?app=admin&m=Circle&a=deleteCircleMessage', {
      ids: selected.id.join()
    })
      .done(function(res) {
    	  console.log(res)
        if (res == '0') {
          alert(lang.delFails)
        } else {
          /*$('#sysdeleteuser').html(res)*/
          alert(lang.delSuccess)
          mygrid.del(selected.index)
        }
      })
  }

})
